<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>

<div id="stream_upload_modal" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
	<div class="modal-dialog modal-lg" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">公司列表</h4>
			</div>
			<div class="modal-body">
				<!--  class="modal-body" -->
				<div class="row">
					<div class="col-md-12">
						<!-- START SIMPLE DATATABLE -->
						<div class="panel panel-default">
							<div class="panel-body">
								<div class="dropzone dz-clickable" id="i_stream_dropzone"></div>
								<div class="btn-toolbar" role="toolbar">
									<div class="btn-group">
										<button type="button" class="btn btn-default" id="i_select_files">添加文件</button>
										<button type="button" class="btn btn-default" onclick="javascript:_t.upload();">开始上传</button>
										<button type="button" class="btn btn-default" onclick="javascript:_t.stop();">暂停上传任务</button>
										<button type="button" class="btn btn-danger hide comfirm_override_transfer_video">覆盖原视频</button>
										<!-- <button type="button" class="btn btn-default" onclick="javascript:_t.cancel();">取消上传</button> -->
									</div>
								</div>
								<table id="data_table" class="table tablesorter">
									<thead>
										<tr><th>编号</th>
											<th>文件</th>
											<th>大小</th>
											<th>操作</th>
										</tr>
									</thead>
									<tbody id="bootstrap-stream-container">
									</tbody>
								</table>
							</div><!-- panel-body -->
						</div><!-- panel -->
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary comfirm">确认选择</button>
			</div>
		</div>
	</div>
</div>





<!-- 
<div class="container">
	<div class="row clearfix">
		<div class="col-md-12 column">
			<div class="page-header">
			<h1>校园平台视频上传 <small>upload</small></h1>
			
			<div class="dropzone dz-clickable" id="i_stream_dropzone">
			</div>
			

			<table id="data_table" class="table tablesorter">
				<thead>
					<tr><th>编号</th>
						<th>文件</th>
						<th>大小</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="bootstrap-stream-container">
				</tbody>
			</table>
		</div>
		
	</div>	
</div>
 -->

<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel" style="font-weight: bold;">视频上传通知</h4>
            </div>
            <div class="modal-body"></div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">确认</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<script type="text/javascript">
	$(function() {
	    $('#myModal').modal('hide');
	    $('#myModal').on('hide.bs.modal', function(){
	    	$(this).find('.modal-body').html('');
	    });
	});
/**
 * 配置文件（如果没有默认字样，说明默认值就是注释下的值）
 * 但是，on*（onSelect， onMaxSizeExceed...）等函数的默认行为
 * 是在ID为i_stream_message_container的页面元素中写日志
 */
 
	var config = {
		enabled: true, /** 是否启用文件选择，默认是true */
		customered: true,
		multipleFiles: true, /** 是否允许同时选择多个文件，默认是false */	
		autoRemoveCompleted: false, /** 是否自动移除已经上传完毕的文件，非自定义UI有效(customered:false)，默认是false */
		autoUploading: true, /** 当选择完文件是否自动上传，默认是true */
		fileFieldName: "FileData", /** 相当于指定<input type="file" name="FileData">，默认是FileData */
		maxSize: 10737418240, /** 当_t.bStreaming = false 时（也就是Flash上传时），2G就是最大的文件上传大小！所以一般需要 */
		simLimit: 1, /** 允许同时选择文件上传的个数（包含已经上传过的） */
		extFilters: [".mp4", ".mpg", ".mpeg", ".avi", ".vob", ".wmv", ".mov", /* ".flv", ".rm", ".rmvb", ".ts" */], /** 默认是全部允许，即 [] */
		browseFileId : "i_select_files", /** 文件选择的Dom Id，如果不指定，默认是i_select_files */
		browseFileBtn : "<div>请选择文件</div>", /** 选择文件的按钮内容，非自定义UI有效(customered:false) */
		dragAndDropArea: "i_stream_dropzone",
		filesQueueId : "i_stream_files_queue", /** 文件上传进度显示框ID，非自定义UI有效(customered:false) */
		filesQueueHeight : 450, /** 文件上传进度显示框的高，非自定义UI有效(customered:false)，默认450px */
		messagerId : "i_stream_message_container", /** 消息框的Id，当没有自定义onXXX函数，系统会显示onXXX的部分提示信息，如果没有i_stream_message_container则不显示 */
		frmUploadURL : "../fd;", /** Flash上传的URI */
      	uploadURL : "../upload",
		tokenURL : "../tk",
		onSelect: function(files) {
		},
		onMaxSizeExceed: function(file) {
			addError("文件[name="+file.name+", size="+file.formatSize+"]超过文件大小限制‵"+file.formatLimitSize+"‵，将不会被上传！<br>");
		},
		onFileCountExceed : function(selected, limit) {
			$('#myModal').modal('show');
			$('#myModal .modal-body').append("同时最多上传<strong>"+limit+"</strong>个文件，但是已选择<strong>"+selected+"</strong>个<br>");
		},
		onExtNameMismatch: function(info) {
			addError("<strong>"+info.name+"</strong>文件类型不匹配[<strong>"+info.filters.toString() + "</strong>]<br>");
		},
		onAddTask: function(file) {
			 var file = '<tr id="' + file.id + '" class="template-upload fade in">' +
		     '<td><span class="preview">'+file.id+'</span></td>' +
		     '<td><p class="name">' + file.name + '</p>' +
		     '    <div><span class="label label-info">进度：</span> <span class="message-text"></span></div>' +
		     '    <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">' +
			'			<div class="progress-bar progress-bar-success" title="" style="width: 0%;"></div>' +
			'		</div>' +
		     '</td>' +
		     '<td><p class="size">' + file.formatSize + '</p>' +
		     '</td>' +
		     '<td>' +
		     '<div class="btn-group">' +
		      //'' + 
		      '<button type="button" class="btn btn-xs btn-danger" onClick="javascript:_t.cancelOne(\'' + file.id + '\')"><i class="glyphicon glyphicon-remove"></i></button>' +
			  '</div>' +
		     '</td></tr>';
			$("#bootstrap-stream-container").append(file);
		},
		onUploadProgress: function(file) {
			var $bar = $("#"+file.id).find("div.progress-bar");
			$bar.css("width", file.percent + "%");
			var $message = $("#"+file.id).find("span.message-text");
			$message.text("已上传:" + file.formatLoaded + "/" + file.formatSize + "(" + file.percent + "%" + ") 速  度:" + file.formatSpeed);
			
			/* var $total = $("#stream_total_progress_bar");
			$total.find("div.progress-bar").css("width", file.totalPercent + "%");
			$total.find("span.stream_total_size").html(file.formatTotalLoaded + "/" + file.formatTotalSize);
			$total.find("span.stream_total_percent").html(file.totalPercent + "%"); */
			
		},
		onStop: function() {
		},
		onCancel: function(file) {
			$("#"+file.id).remove();
			/* var $total = $("#stream_total_progress_bar");
			$total.find("div.progress-bar").css("width", file.totalPercent + "%");
			$total.find("span.stream_total_size").text(file.formatTotalLoaded + "/" + file.formatTotalSize);
			$total.find("span.stream_total_percent").text(file.totalPercent + "%"); */
		},
		onCancelAll: function(numbers) {
			$("#i_info_tips > span.text-message").append(numbers + " 个文件已被取消上传！！！");
		},
		onComplete: function(file) {
			/** 100% percent */
			var $bar = $("#"+file.id).find("div.progress-bar");
			$bar.css("width", file.percent + "%");
			var $message = $("#"+file.id).find("span.message-text");
			$message.text("已上传:" + file.formatLoaded + "/" + file.formatSize + "(" + file.percent + "%" + ")");
			/** remove the `cancel` button */
			var $cancelBtn = $("#"+file.id).find("td:last > span");
			$cancelBtn.remove();
			
			/** modify the total progress bar */
			/* var $total = $("#stream_total_progress_bar");
			$total.find("div.progress-bar").css("width", file.totalPercent + "%");
			$total.find("span.stream_total_size").text(file.formatTotalLoaded + "/" + file.formatTotalSize);
			$total.find("span.stream_total_percent").text(file.totalPercent + "%");
			 */
			
			var now = new Date();
			var onLineTimeStr = now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate() + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
			var offLineTimeStr = (now.getFullYear()+10)+"-"+(now.getMonth()+1)+"-"+now.getDate() + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
			
			var rename = eval("(" + file.msg + ")").rename;
			var filename = file.name.split(".")[0];
			
			$comfirm_override_transfer_video = $("#stream_upload_modal").find("button.comfirm_override_transfer_video");
			$comfirm_override_transfer_video.removeClass("hide");
			$comfirm_override_transfer_video.on("click", function(){
				$.ajax({
					url: "update_content_code.do",
					data: {f_cc_id : window.stream_upload_content_id, f_cc_code: rename,stime : "<%=ConstantUtils.getNonceObject()[0]%>",sign : "<%=ConstantUtils.getNonceObject()[1]%>"},
					dataType: "json",
					type: "POST",
					success: function(data) {
						if(data.success) {
							alert("覆盖成功！");
							window.location.reload();
						} else {
							alert("覆盖失败！");
						}
					}
				});
			});
			
			//var params = 'videoJson=%5B%5D&f_cc_isfree=0&f_cc_status=2&f_cc_name=' + filename +'&f_cc_searchname=&f_cc_companyid=' + orgId + '&f_cc_tags=&f_cc_type=7&f_cc_director=&f_cc_onlinedate=' + encodeURIComponent(onLineTimeStr) + '&f_cc_actors=&f_cc_offlinedate=' + encodeURIComponent(offLineTimeStr) + '&f_cc_screenwriter=&f_cc_code=' + encodeURIComponent(rename) + '&f_cc_seriescount=1&f_cc_end=0&picJson=%5B%5D&f_cc_desc=';
			/* app_ajax('insert_content.do', params, function(data) {
				if (data.success) {
					$('#myModal').modal('show');
					$('#myModal .modal-body').append(file.name + "上传成功!<br/>");
				} else {
					$('#myModal').modal('show');
					$('#myModal .modal-body').append(file.name + "上传失败! " + data.result + "<br/>");
				}
			}); */
		},
		onQueueComplete: function(msg) {
		},
		onUploadError: function(status, msg) {
			$("#i_info_tips > span.text-message").append(msg + ", 状态码:" + status);
		}
	};
	var _t = new Stream(config);
	/** 不支持拖拽，隐藏拖拽框 */
	if (!_t.bDraggable) {
		$("#i_stream_dropzone").hide();
	}
	/** Flash最大支持2G */
	if (!_t.bStreaming) {
		//_t.config.maxSize = 2147483648;
		_t.config.maxSize = 10737418240
	}
	
	
</script>
